// -----------------------------------------------------------------------
// <copyright file="UserLog.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Data.SqlClient;
    using AdCom.Utility;
    using VDC.COMMON;
    
    /// <summary>
    /// Class UserLog
    /// </summary>
    public class UserLog
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UserLog" /> class
        /// </summary>
        public UserLog()
        {
            this.UserLogId = 0;
            this.UserId = 0;
            this.DepartmentId = 0;
            this.FunctionId = 0;
            this.Even = string.Empty;
            this.Date = null;
            this.Descriptions = string.Empty;
        }

        /// <summary>
        /// Gets or sets UserLogId
        /// </summary>
        public int UserLogId { get; set; }

        /// <summary>
        /// Gets or sets UserId
        /// </summary>
        public int UserId { get; set; }

        /// <summary>
        /// Gets or sets DepartmentId
        /// </summary>
        public int DepartmentId { get; set; }

        /// <summary>
        /// Gets or sets FunctionId
        /// </summary>
        public int FunctionId { get; set; }

        /// <summary>
        /// Gets or sets Even
        /// </summary>
        public string Even { get; set; }

        /// <summary>
        /// Gets or sets Date
        /// </summary>
        public DateTime? Date { get; set; }

        /// <summary>
        /// Gets or sets Descriptions
        /// </summary>
        public string Descriptions { get; set; }

        /// <summary>
        /// Gets User
        /// </summary>
        public User User
        {
            get
            {
                try
                {
                    User user = null;
                    SqlDataReader reader = SqlDataHelper.ExecuteReader(string.Format(Constants.StorepProcedure.VOneUsersGetById, this.UserId));

                    while (reader.Read())
                    {
                        user = new User();

                        if (!reader.IsDBNull(0))
                        {
                            user.UserId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            user.AdministrativeUnitsId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            user.UserName = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            user.FullName = reader.GetString(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            user.Sex = reader.GetBoolean(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            user.BirthDate = reader.GetDateTime(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            user.Email = reader.GetString(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            user.Sms = reader.GetString(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            user.Phone = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            user.Address = reader.GetString(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            user.CreateDate = reader.GetDateTime(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            user.Send = reader.GetString(11);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return user;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets Department
        /// </summary>
        public Department Department
        {
            get
            {
                try
                {
                    Department department = null;
                    SqlDataReader reader = SqlDataHelper.ExecuteReader(string.Format(Constants.StorepProcedure.VOneDepartmentGetById, this.DepartmentId));

                    while (reader.Read())
                    {
                        department = new Department();

                        if (!reader.IsDBNull(0))
                        {
                            department.DepartmentId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            department.Code = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            department.Name = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            department.Parent = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            department.Order = reader.GetInt32(4);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return department;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
